package com.sl.plugin.step.selenium.windows;

import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.StrUtil;
import com.sl.core.engine.data.impl.AbstractProcessCompContext;
import com.sl.core.engine.meta.impl.AbstractProcessCompDescriptor;
import com.sl.core.engine.step.ProcessCompService;
import com.sl.core.engine.step.impl.AbstractProcessComp;
import org.apache.hop.pipeline.Pipeline;
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.transform.TransformMeta;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;

import java.io.File;

/**
 */
public class SeleniumWindowsComp extends AbstractProcessComp<WebDriver, WebDriver> implements ProcessCompService {


    public SeleniumWindowsComp(AbstractProcessCompDescriptor abstractProcessCompDescriptor) {
        super(abstractProcessCompDescriptor);
    }

//
//    public SeleniumWindowsComp(TransformMeta transformMeta, AbstractProcessCompDescriptor meta, AbstractProcessCompContext data, int copyNr, PipelineMeta pipelineMeta, Pipeline pipeline) {
//        super(transformMeta, meta, data, copyNr, pipelineMeta, pipeline);
//    }

    @Override
    public WebDriver input(WebDriver driver) {
        Boolean closeFlag = meta.getBoolAttr("closeFlag");
        Boolean quitFlag = meta.getBoolAttr("quitFlag");
        Boolean maxWindowFlag = meta.getBoolAttr("maxWindowFlag");
        Boolean minWindowFlag = meta.getBoolAttr("minWindowFlag");
        Boolean fullScreenFlag = meta.getBoolAttr("fullScreenFlag");


        if (BooleanUtil.isTrue(maxWindowFlag)) {
            driver.manage().window().maximize();
        }
        if (BooleanUtil.isTrue(minWindowFlag)) {
            driver.manage().window().minimize();
        }
        if (BooleanUtil.isTrue(fullScreenFlag)) {
            driver.manage().window().fullscreen();
        }

        if (BooleanUtil.isTrue(closeFlag)) {
            driver.close();
            return driver;
        }
        if (BooleanUtil.isTrue(quitFlag)) {
            driver.quit();
            return null;
        }
        return driver;
    }


}
